class AdminController < ApplicationController
  def index
    list
    render :action => 'list'
  end

  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
  verify :method => :post, :only => [ :destroy, :create, :update ],
         :redirect_to => { :action => :list }

  def list
    if params[:id] == nil
      @thing_pages, 
      @things = paginate :things, :per_page => 20, :order => "deadline, priority"
    else
      @thing_pages, 
      @things = paginate :things, :per_page => 20, :order => "deadline, priority", 
                          :conditions => "category = '" + params[:id] + "' "
    end
  end

  def show
    @thing = Thing.find(params[:id])
  end

  def new
    @thing = Thing.new
  end

  def create
    @thing = Thing.new(params[:thing])
    if @thing.save
      flash[:notice] = 'Thing was successfully created.'
      redirect_to :action => 'list'
    else
      render :action => 'new'
    end
  end

  def edit
    @thing = Thing.find(params[:id])
  end

  def update
    @thing = Thing.find(params[:id])
    if @thing.update_attributes(params[:thing])
      flash[:notice] = 'Thing was successfully updated.'
      redirect_to :action => 'show', :id => @thing
    else
      render :action => 'edit'
    end
  end

  def destroy
    Thing.find(params[:id]).destroy
    redirect_to :action => 'list'
  end
end
